#include "BlockQueue.hpp"

#include <string>

struct TreadData
{
    BlockQueue<int>* bq;
    std::string name;
};

void* consumer(void* args)
{
    TreadData* td = static_cast<TreadData*>(args);
    while(true)
    {
        sleep(1);
        int out = 0;
        td->bq->Pop(&out);
        std::cout << "消费者消费了一个数据：" << out << std::endl;
    }
}

void* productor(void* args)
{
    TreadData* td = static_cast<TreadData*>(args);
    int data = 1;
    while(true)
    {
        td->bq->Enqueue(data);
        std::cout << "生产者生产了一个数据：" << data++ << std::endl;
    }
}

int main()
{
    pthread_t c, p;
    BlockQueue<int> bq;
    TreadData ctd = {&bq, "消费者"};
    pthread_create(&c, nullptr, consumer, (void*)&ctd);

    TreadData ptd = {&bq, "生产者"};
    pthread_create(&p, nullptr, productor, (void*)&ptd);

    pthread_join(c, nullptr);
    pthread_join(p, nullptr);
    return 0;
}